﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Vehicle.Web.Pages.Recycle
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Admin_Main.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-09-04   Created by 陈天铸 V1.00.0000
    /// 功能说明：用户信息页面类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Admin_Main : Component.PageBase
    {
        #region---基本变量实例化---
        Vehicle.BLL.Admin b_Admin = new Vehicle.BLL.Admin();
        Vehicle.Model.ComponentsInfo m_ComponentsInfo = new Vehicle.Model.ComponentsInfo();
        public string onshow;//定义没有数据时页面的显示内容
        #endregion

        #region---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lbtn_AllDelete.Attributes.Add("onClick", "return confirm('是否要删除这些用户');");
                b_Admin.DropDownListBind1(Drop_Select);//绑定角色
                RepeaterDataBind();//绑定数据
                Drop_News.SelectedValue = "1";
            }
        }
        /// <summary>
        /// 绑定页面Repeater数据
        /// </summary>
        public void RepeaterDataBind()
        {
            //如果选择为全部则选择值为0 通用实体层匹配条件为1 结果为1  Drop_Select.SelectedValue == "0" ? "1": Drop_Select.SelectedValue
            this.Anp_Page.RecordCount = b_Admin.GetAllSearchCount(new Vehicle.Model.ComponentsInfo("Admin", Drop_Select.SelectedValue == "0" ? "1" : "R_ID", Drop_Select.SelectedValue == "0" ? "1" : Drop_Select.SelectedValue, "A_IsDelete", "1", "A_ID"));//更具下拉菜单选择的进行数据绑定
            m_ComponentsInfo.startIndex = Anp_Page.StartRecordIndex;//当前页的起始索引
            m_ComponentsInfo.endIndex = Anp_Page.EndRecordIndex;//当前页的结束索引
            m_ComponentsInfo.condition = Drop_Select.SelectedValue == "0" ? "1" : "R_ID";//条件一
            m_ComponentsInfo.result = Drop_Select.SelectedValue == "0" ? "1" : Drop_Select.SelectedValue;//匹配结果一
            m_ComponentsInfo.Tcondition = "A_IsDelete";//条件二
            m_ComponentsInfo.Tresult = "1";//匹配结果二
            b_Admin.RepeaterBind(ReptShow, m_ComponentsInfo);//绑定Repeater控件
            if (ReptShow.Items.Count == 0)//判断没有数据时页面的显示内容
            {
                onshow = "当前页面无数据";
            }
            else
            {
                onshow = "";
            }

        }
        /// <summary>
        /// 根据角色选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Drop_Select_SelectedIndexChanged(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }
        /// <summary>
        /// ReptShow激发事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                b_Admin.Delete(new Vehicle.Model.ComponentsInfo("Admin", "A_ID", e.CommandArgument.ToString()));//删除数据
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
        }
        /// <summary>
        /// ReptShow绑定数据事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((LinkButton)(e.Item.FindControl("Lbtn_Delete"))).Attributes.Add("onClick", "return   confirm('您确定删除该用户？');");
                Label lab_R_ID = (Label)e.Item.FindControl("lab_R_ID");
                try
                {
                    lab_R_ID.Text = b_Admin.GetModel(new Vehicle.Model.ComponentsInfo("Role", "R_ID", lab_R_ID.Text, "R_ID")).Rows[0]["R_Name"].ToString();//绑定角色
                }
                catch 
                {
                    lab_R_ID.Text = "无";
                }
            }
        }
        /// <summary>
        /// 分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }
        /// <summary>
        /// 全部删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtn_AllDelete_Click(object sender, EventArgs e)
        {
            int Count = 1;
            foreach (RepeaterItem item in ReptShow.Items)
            {
                CheckBox chk = (CheckBox)item.FindControl("Chk_Num");
                if (chk.Checked)
                {
                    Count++;
                    b_Admin.Delete(new Vehicle.Model.ComponentsInfo("Admin", "A_ID", chk.ToolTip));//删除数据
                }
            }
            if (Count > 1)
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                RepeaterDataBind();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('您还没有进行选择！')", true);
            }
        }
       
        /// <summary>
        /// 信息选择事件跳转到相应页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Drop_News_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (Drop_News.SelectedValue)
            {
                case "1": Response.Redirect("Admin_Main.aspx"); break;//选择用户信息页
                case "2": Response.Redirect("Motorcade_Main.aspx"); break;//选择车队信息页
                case "3": Response.Redirect("Vehicles_Main.aspx"); break;//选择车辆信息页
                case "4": Response.Redirect("Task_Main.aspx"); break;//选择任务信息页
                case "5": Response.Redirect("Expense_Main.aspx"); break;//选择费用信息页
                case "6": Response.Redirect("Pilot_Main.aspx"); break;//选择驾驶员信息页
                case "7": Response.Redirect("Cargo_Main.aspx"); break;//选择承运单信息页
            }
        }
        #endregion
    }
}
